import React, { Component } from "react";
import axios from "axios";

export default class Search extends Component {

  //搜索
  handleSearch = () => {
    // let value = this.keywordElement.value;
    const {keywordElement:{value:keyword}} = this;
    console.log(keyword);
    let url = "/api/back/backDist/getEffectivenessCount"
    let params = {"pidLevel":"SY01", keyword}
    this.props.updateAppState({"isFirst": false, "isLoading": true})
    axios.post(url, params).then(res => {
      if(res.status === 200) {
        let data = res.data.result;
        this.props.updateAppState({ "isLoading": false, "users": data.data || []})
      }
    }).catch(err => {
      console.log(err);
      this.props.updateAppState({"err": err.message, "isLoading": false})
    })
  }

  render() {
    return (
      <section className="jumbotron">
        <h3 className="jumbotron-heading">搜索github 用户</h3>
        <div>
          <input ref={(c) => this.keywordElement = c} type="text" placeholder="请输入关键词" />
          <button onClick={this.handleSearch}>搜索</button>
        </div>
      </section>
    );
  }
}
